package cn.isjinhao.crws.sql.lexical.token;

import java.util.Objects;

/**
 * @Author ISJINHAO
 * @Date 2021/2/20 17:03
 */
public class Token {

    private final TokenType type;
    /**
     * 存 number、string、true、false、null
     */
    private final Object literal;

    public Token(TokenType type, Object literal) {
        this.type = type;
        this.literal = literal;
    }

    public Token(TokenType type) {
        this.type = type;
        this.literal = null;
    }

    @Override
    public String toString() {
        return "Token {" +
            "type: " + type +
            ", literal: " + literal +
            "}";
    }

    public TokenType getType() {
        return type;
    }

    public Object getLiteral() {
        return literal;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Token token = (Token) o;
        return type == token.type && Objects.equals(literal, token.literal);
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, literal);
    }
}